#units are MGD

files = c('bay-discharge.csv','plant-inflow.csv','wetland-effluent.csv','wetland-influent.csv')

bayDischarge = as.matrix(read.table(files[1],fill=T,header=T)) 
plantInflow = as.matrix(read.table(files[2],fill=T,header=T)) 
wetlandOutflow = as.matrix(read.table(files[3],fill=T,header=T)) 
wetlandInflow = as.matrix(read.table(files[4],fill=T,header=T)) 


pdf("arcata-wwtp-plots.pdf",width = 15)
     

for(i in 1:4){
    if(i ==1) {
        data = bayDischarge 
        lab = "Bay Discharge (MGD)" 
        lim = c(0,35)
        
    }
    if(i ==2) {
        data = plantInflow  
        lab = "Plant Inflow (MGD)"
        lim = c(0,25)
    }
    if(i ==3) {
        data = wetlandOutflow  
        lab = "Wetland Outflow (MGD)"
        lim = c(0,5)
    }
    if(i ==4) {
        data = wetlandInflow  
        lab = "Wetland Inflow (MGD)"
        lim = c(0,10)
    }
    
    data[data==-9999] = NA 
    tstamp = data[,1]*10000+data[,2]*100+data[,3]
    tstamp = as.POSIXlt(as.character(tstamp), tz = "PDT", format = "%Y%m%d")
    
    plot(tstamp, data[,4], ylim = lim, type='n', ylab = lab)
    
    ind = 1:nrow(data)
    ind = ind[!is.na(data[,5])]
    for(i in 1:length(ind))  lines(c(tstamp[ind[i]],tstamp[ind[i]]),c(-5,100), col='red')
    
    lines(tstamp, data[,4])
}

dev.off()
